/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package old;

import java.io.IOException;
import org.apache.commons.codec.language.Metaphone;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;

public class MetaphoneReplacementFilter extends TokenFilter {
    
    public static final String METAPHONE = "METAPHONE";
    private Metaphone metaphoner = new Metaphone();
    
    public MetaphoneReplacementFilter(TokenStream input) {
        super(input);
    }
    
    public Token next() throws IOException {
        Token t = input.next();
        if (t == null) return null;    
        return new Token(metaphoner.encode(t.termText()), t.startOffset(),t.endOffset(),METAPHONE);
    }
}
